package com.owen.java.demo.aviator;

import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.AviatorEvaluatorInstance;
import com.googlecode.aviator.Expression;
import org.junit.Test;

/**
 * 官方文档：
 * https://www.yuque.com/boyan-avfmj/aviatorscript
 */
public class HelloWorld {

    @Test
    public void test01(){
        AviatorEvaluatorInstance instance = AviatorEvaluator.getInstance();
        String expression="println('Hello, AviatorScript!')";
        instance.execute(expression);
    }

    @Test
    public void test02(){
        String expression="a-(b-c)>100";
        // AviatorEvaluator.compile 是 AviatorEvaluator.getInstance().compile 的等价方法。
        Expression compiledExp=AviatorEvaluator.compile(expression);
        // Execute with injected variables.
        Boolean result=(Boolean) compiledExp.execute(compiledExp.newEnv("a",100.3,"b",45,"c",-199.100));
        System.out.println(result);
    }

    @Test
    public void test03(){
        String expression="a+b+c";
        Expression compiledExp=AviatorEvaluator.compile(expression);
        Object result=compiledExp.execute(compiledExp.newEnv("a",10,"b",20,"c",30));
        System.out.println(result);
    }

}
